﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using LX.Core.Auth;
using LX.Core.Data;
using LX.Data;
using LX.ExceptionHanding;
using LX.Log;

namespace LX.Data
{


    /// <summary>
    /// 应用服务
    /// </summary>
    public abstract class ApplicationService
    {
        /// <summary>
        /// 执行上下文
        /// </summary>
        public IApplicationServiceContext Context { get; set; }

        public IApplicationServiceContext In(System.Reflection.MethodBase methodinfo)
        {
            return Context.RunIn(methodinfo);
        }

        protected void Do(Action<ApplicationTransaction> fun)
        {
            var st = new StackTrace(true); 
            In(st.GetFrame(1).GetMethod()).Do(fun);
        }

        protected T Do<T>(Func<ApplicationTransaction, T> fun)
        {
            var st = new StackTrace(true);
            return In(st.GetFrame(1).GetMethod()).Do(fun);
        }
    }
}
